package com.chinasoft.maysham.manager.config;

import com.chinasoft.maysham.manager.model.User;
import com.chinasoft.maysham.manager.util.AuthUtil;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class MongoAuditorAwareImpl implements AuditorAware<String> {

    @Override
    public Optional<String> getCurrentAuditor() {
        User user = AuthUtil.currentUser();
        if (user == null) {
            return Optional.empty();
        }
        String id = user.getId();
        return Optional.of(id == null ? "" : id);
    }
}
